package com.whosly.strategy.manager;

import com.whosly.strategy.IStrategy;
import com.whosly.strategy.container.IStrategyContainer;
import com.whosly.strategy.scan.ContainerProxy;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author yueny09 <deep_blue_yang@126.com>
 * @Date 2019-09-06 13:58
 */
public class ContainerProxyManager<C, S extends IStrategy<C>, T extends IStrategyContainer<C, S>> {
    private static ContainerProxyManager holder;
    public static ContainerProxyManager get(){
        if(holder == null){
            synchronized (ContainerProxyManager.class){
                if(holder == null){
                    holder = new ContainerProxyManager();
                }
            }
        }

        return holder;
    }

    private final Map<String, ContainerProxy<C, S, T>> factory = new HashMap<>();

    public void registry(String strategyContainerName, ContainerProxy<C, S, T> containerProxy) {
        factory.put(strategyContainerName, containerProxy);
    }

    public Set<String> getKeys() {
        return factory.keySet();
    }

    public Collection<ContainerProxy<C, S, T>> getProxys() {
        return factory.values();
    }

    public void clear() {
        factory.clear();
    }
}
